package com.xmsx.back.service.admin;

import com.xmsx.back.mapper.admin.JobMapper;
import com.xmsx.back.pojo.Job;
import com.xmsx.back.utils.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class JobService {
    @Autowired
    JobMapper jobMapper;

    /**
     *获取某个招聘信息的所有数据
     * @param id
     * @return
     */
    public Job getById(int id) { return jobMapper.getById(id); }

    /**
     * 插入招聘信息
     * @param job
     */
    public void setJob(Job job) { jobMapper.setJob(job); }

    /**
     * 修改招聘信息
     * @param job
     */
    public void updateJob(Job job) { jobMapper.updateJob(job); }

    /**
     * 删除招聘信息
     * @param id
     */
    public void deleteJob(int id) { jobMapper.deleteJob(id); }

    /**
     * 分页查找多条数据
     *
     * @param page
     * @param size
     * @return
     */
    public Pager<Job> findByPager(int page, int size) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page - 1) * size);
        params.put("size", size);
        Pager<Job> pager = new Pager<Job>();
        List<Job> list = jobMapper.findByPager(params);
        pager.setRows(list);
        pager.setTotal(jobMapper.count());
        return pager;
    }
}
